<template>
  <view
    style="
      width: 800px;
      text-align: center;
      display: inline-block;
      flex-wrap: wrap;
    "
  >
    <view class="machine-list-card" v-for="item in myGoodsList" :key="item.id">
      <view style="display: flex">
        <view class="left">
          <view class="img"><img :src="item.img" class="img" /></view>
        </view>
        <view class="right">
          <view class="info-item">
            <view class="info-item-title">{{ item.title }}</view>
          </view>
          <view class="info-item">
            <view class="info-item-title">{{ item.describe }}</view>
          </view>
          <view class="info-item">
            <view class="info-item-title">¥{{ item.price }}</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>
<script setup>
import { getgoodlist } from "../utils/good";
import { inject, onMounted, onUpdated, ref, toRaw, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useStore } from "vuex";
const myGoodsList = ref([]);
const mygoodtype = ref("");
const cartlist = ref([]);
const route = useRoute();
const router = useRouter();
const store = useStore();
function getcontent() {
  let ss = route.query.goodclass;
  // if (ss == "big" || ss == "median" || ss == "small") {
  //   myGoodsList.value = store.getters.getMyGoodsList;
  //   console.log("goodsrelate:", route.query.goodclass);
  //   cartlist.value = myGoodsList.value.filter((item) => {
  //     return toRaw(item).goodclass.match(ss);
  //   });
  // }else{
    getgoodlist({goodtype: ss})
    .then((response) => {
      myGoodsList.value.splice(0, myGoodsList.value.length); //清空数组
      for (let index in response.rows) {
        let newgood = {
          id: response.rows[index],
          img: "/a1.jpg",
          title: "测试",
          describe: "新产品",
          price: 121,
          num: 3,
          memo: "无",
        };

        response.rows[index].img =
          "http://localhost/dev-api" + response.rows[index].img;
        newgood.id = response.rows[index].id;
        newgood.img = response.rows[index].img;
        newgood.title = response.rows[index].title;
        newgood.describe = response.rows[index].mydescribe;
        newgood.price = response.rows[index].price;
        newgood.num = response.rows[index].num;
        newgood.memo = response.rows[index].memo;
        myGoodsList.value.push(newgood);
      }
    })
    .catch((err) => {
      console.log(err);
    });
  // }
  
}
watch(mygoodtype, async (newValue, oldValue) => {
  getcontent();
});
onMounted(() => {
  getcontent();
});
onUpdated(() => {
  mygoodtype.value = route.query.goodclass;
});
</script>
<style scoped>
.machine-list-card {
  /* width: 850px; */
  height: 100px;
  /* margin: 5px auto; */
  display: flex;
  flex-direction: row;
  background-color: #ffffff;
  border-radius: 10px;
  box-shadow: 5px 5px 10px rgba(160, 160, 160, 0.3);
  margin-bottom: 10px;
  /* margin-right: 10px; */
}

.check1 {
  width: 80px;
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.left {
  width: 80px;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.right {
  min-width: 600px;
  height: 100px;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  /* flex-direction: column; */
  justify-content: space-around;
}

.img {
  width: 80px;
  height: 80px;
}

.img image {
  width: 80px;
  height: 80px;
}

.info-item {
  display: flex;
  white-space: nowrap;
  display: inline-grid;
  align-content: center;
}

.info-item-title {
  /* font-weight: bold; */
  font-size: 20px;
  width: 4em;
  text-align: justify;
  text-align-last: justify;
}

.info-item-content {
  margin-left: 10px;
  overflow: hidden;
}
</style>
